package com.ita.filter;

import java.util.ArrayList;
import java.util.List;

import com.ita.entity.Customer;

public class CustomerFilter implements RegexFilter {

	
	public ArrayList<Customer> doFilter(List<String> list) {

		for (int i = 0; i < list.size(); i++) {
			String string = list.get(i).replaceAll(EMPTY_REGEX, " ");
			String email = string.split(" ")[2];
			String birthday = string.split(" ")[4];
			if (!(email.matches(EMAIL_REGEX) && birthday.matches(BIRTHDAY_REGEX))) {
				list.remove(i);
			}
		}
		return generateCustomers(list);
		
	}

	public ArrayList<Customer> generateCustomers(List<String> legalList) {
		
//		doFilter(legalList);
		ArrayList<Customer> customers = new ArrayList<Customer>();
		for (String string : legalList) {
			Customer customer = new Customer();
			customer.setId(string.split(" ")[0]);
			customer.setName(string.split(" ")[1]);
			customer.setEmail(string.split(" ")[2]);
			customer.setSex(string.split(" ")[3]);
			customer.setBirthday(string.split(" ")[4]);
			customers.add(customer);
		}
		return customers;

	}


}
